package com.ruku.RuKumapper;

import com.bean.WmsTBill;
import com.bean.WmsTBillDetails;
import com.bean.WmsTCustomer;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

public interface RuKuMapper {

    //入库模糊查询
    @Select("select * from wms_t_customer where custName like '%${value}%'")
    public List<WmsTCustomer> rukuselectCusmer(String custName);

    //将入库办理数据写入wmstbill表
    @Insert("insert into wms_t_bill (billID,billTransactor,customerID,billState,billDate,billType,billFeeTruckage,billFeeStore,billFeeOther,billPayable,billPaid,billEditTime,billIsDel) values (#{billId},#{billTransactor},#{customerId},#{billState},#{billDate},#{billType},#{billFeeTruckage},#{billFeeStore},#{billFeeOther},#{billPayable},#{billPaid},#{billEditTime},#{billIsDel})")
    public void ruKuBanLiSetWmstBill(WmsTBill wmsTBill);

    //验货装盘
    @Select("select * from wms_t_bill LEFT JOIN wms_t_customer on wms_t_bill.customerID = wms_t_customer.custID where wms_t_bill.billType = 0 and wms_t_bill.billState = 0")
    public List<WmsTBill> selectAllYbzpan();

    @Select("select * from wms_t_bill_details where billID = #{choosebillId}")
    public List<WmsTBillDetails> selectAllBiDeTailsBybillId(String choosebillId);
    //应该用List<WmsTBillDetails>,但拿不到值

    //验货装盘删除
    @Delete("delete from wms_t_bill_details where detailsID = #{choosebillDetilId}")
    public void deleteYanHuoBydetailsId(String choosebillDetilId);

    //验货结束，修改billState为1
    @Update("update wms_t_bill set billState = '1' where  billID = #{choosebillId}")
    public void updateBillStateBybillId(String choosebillId333);

    //--------------------------------------------------------------------------------
    //入库结算  billState='2'
    @Select("select * from wms_t_bill LEFT JOIN wms_t_customer on wms_t_bill.customerID = wms_t_customer.custID where wms_t_bill.billType = 0 and wms_t_bill.billState = 1")
    public List<WmsTBill> selectBillByrkjSuan();

    @Update("update wms_t_bill set billState = #{billState},billFeeTruckage = #{billFeeTruckage},billFeeOther = #{billFeeOther},billPayable = #{billPayable} where billID = #{billId}")
    public void updateBillByrkjsuan(WmsTBill wmsTBill);

    @Select("<script>" +
            "SELECT wms_t_bill.*,wms_t_customer.custName,wms_t_bill_details.*  from wms_t_bill \n" +
            "LEFT JOIN wms_t_customer on wms_t_bill.customerID = wms_t_customer.custID \n" +
            "LEFT JOIN wms_t_bill_details on wms_t_bill.billID = wms_t_bill_details.billID \n" +
            "WHERE billType='0' and billState='2' and billIsDel='0' " +
            "<if test=\"huozhuName != '' \">" +
            " and wms_t_bill.customerID in(SELECT custID FROM wms_t_customer WHERE wms_t_customer.custName = #{custName} ) " +
            "</if>" +
            "<if test=\"billDate != '' and billEditTime != ''\">" +
            " and wms_t_bill.billDate BETWEEN #{billDate} AND #{billEditTime}" +
            "</if>" +
            "<if test=\"rukudanhao != '' \">" +
            " and wms_t_bill.billId = #{rukudanhao}" +
            "</if>" +
            "</script>")
            public List<Map<String,Object>> selectAllByMap(String billDate, String billEditTime, String huozhuName,String rukudanhao);
    //--------------------------------------------------------------------------------
    //入库单，，






    // 入库单明细  billState='3'   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    @Select("<script>" +
            "SELECT wms_t_bill.*,wms_t_customer.custName,wms_t_bill_details.*  from wms_t_bill \n" +
            "LEFT JOIN wms_t_customer on wms_t_bill.customerID = wms_t_customer.custID \n" +
            "LEFT JOIN wms_t_bill_details on wms_t_bill.billID = wms_t_bill_details.billID \n" +
            "WHERE billType='0' and billState='2' and billIsDel='0' " +
            "<if test=\"huozhuName != '' \">" +
            " and wms_t_bill.customerID in(SELECT custID FROM wms_t_customer WHERE wms_t_customer.custName = #{custName} ) " +
            "</if>" +
            "<if test=\"billDate != '' and billEditTime != ''\">" +
            " and wms_t_bill.billDate BETWEEN #{billDate} AND #{billEditTime}" +
            "</if>" +
            "<if test=\"rukudanhao != '' \">" +
            " and wms_t_bill.billId = #{rukudanhao}" +
            "</if>" +
            "</script>")
    public List<Map<String,Object>> selectAllByRuKuDan(String billDate, String billEditTime, String huozhuName,String rukudanhao);


    @Update("update wms_t_bill set billState = '3' where billID = (select billID from wms_t_bill_details where detailsID = #{mingxibianhao})")
    public void tuJiaoFromHWRku(String mingxibianhao);



    //货物入库        入库单明细查询
    @Select("select * from wms_t_bill_details where detailsID = #{eveBillsRuKuId}")
    public WmsTBillDetails selectDetilsByHeId(String eveBillsRuKuId);


    //入库单查询
    @Select("<script>" +
            "SELECT wms_t_bill.*,wms_t_customer.custName  from wms_t_bill LEFT JOIN wms_t_customer on wms_t_bill.customerID = wms_t_customer.custID WHERE billType='0' and billState='3' and billIsDel='0' " +
            "<if test=\"huozhuName != '' \">" +
            " and wms_t_bill.customerID in(SELECT custID FROM wms_t_customer WHERE wms_t_customer.custName = #{huozhuName} ) " +
            "</if>" +
            "<if test=\"billDate != '' and billEditTime != ''\">" +
            " and wms_t_bill.billDate BETWEEN #{billDate} AND #{billEditTime}" +
            "</if>" +
            "<if test=\"rukudanhao != '' \">" +
            " and wms_t_bill.billId = #{rukudanhao}" +
            "</if>" +
            "</script>")
    public List<WmsTBill> selectAllByRuKuDanChaXun(String billDate, String billEditTime, String huozhuName,String rukudanhao);



    @Select("select * from wms_t_bill LEFT JOIN wms_t_customer on wms_t_bill.customerID = wms_t_customer.custID where wms_t_bill.billID = #{eveBillsRuKuDanId}")
    public WmsTBill selectBillsByHeId(String eveBillsRuKuDanId);

    @Update("update wms_t_bill set billIsDel = '1' where billID = #{rukudanhao1}")
    public boolean updateWmsBills1Byrukudanhao(String rukudanhao1);

    @Update("update wms_t_bill set billFeeTruckage = #{lizifei1},billDate = #{yewushijian1},billEditTime = #{zuihoubianjishijian1},billState = #{danjuzhuangtai1} where billID = #{rukudanhao1}")
    public boolean updateWmsBills2Byrukudanhao(String rukudanhao1,String lizifei1,String yewushijian1,String zuihoubianjishijian1,String danjuzhuangtai1);
}
